//
//  DRProgressHuanxingView.m
//  ObjectiveCTools
//
//  Created by aidong on 2022/1/6.
//  Copyright © 2022 姬友大人. All rights reserved.
//

#import "DRProgressHuanxingView.h"

@implementation DRProgressHuanxingView

- (instancetype)init {
    if (self = [super init]) {
        self.colorBack = UIColor.greenColor;
        self.colorTint = UIColor.redColor;
        self.lineWidth = 10;
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.colorBack = UIColor.greenColor;
        self.colorTint = UIColor.redColor;
        self.lineWidth = 10;
    }
    return self;
}

- (void)setProgress:(CGFloat)progress {
    _progress = progress;
    dispatch_async(dispatch_get_main_queue(), ^{
        [self setNeedsDisplay];
    });
}

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineCap(context, kCGLineCapButt);
    CGContextSetLineWidth(context, self.lineWidth);  //线宽
    CGContextSetAllowsAntialiasing(context, true);
    CGContextSetStrokeColorWithColor(context, self.colorTint.CGColor);  //线的颜色
    //绘制扇形。参数：1+2，圆点坐标。参数3+4，起点和终点的弧度。参数5:0表示顺时针，1表示逆时针。
    CGContextAddArc(context, self.bounds.size.width / 2.0f, self.bounds.size.height / 2.0f, self.bounds.size.width / 2.0f - 0.5 * self.lineWidth, -M_PI_2, 2 * M_PI * self.progress - M_PI_2, 0);
    //if (self.progress == 0) {
    //    CGContextClearRect(context, self.bounds);
    //} else {
    //}
    CGContextStrokePath(context);
}
@end
